﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsDuLieuChiNhanh
    {
        private string mDatabaseLocal = "";
        private string mKhoaDoiTuong = "";
        private string mKhoaKho = "";
        private int mLoai = 0;
        private string mMatKhau = "";
        private string mNguoiDung = "";
        private string mTenDataBase = "";
        private string mTenMayChu = "";

        public bool Load(string strKhoaDoiTuong, int IntLoai)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM HT_DataClient WHERE KhoaDoiTuong = '" + strKhoaDoiTuong + "' And Loai = " + Conversions.ToString(IntLoai);
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoaDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mLoai = Conversions.ToInteger(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetInt32));
                    this.mTenMayChu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mTenDataBase = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mNguoiDung = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mMatKhau = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mDatabaseLocal = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKho = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    dataReader.Close();
                    return true;
                }
                dataReader.Close();
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag2;
            IDataParameter[] commandParameters = new IDataParameter[8];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[1] = DBHelper.createParameter("@Loai", DbType.Double, ParameterDirection.Input, this.mLoai);
                commandParameters[2] = DBHelper.createParameter("@TenMayChu", DbType.Int64, ParameterDirection.Input, this.mTenMayChu);
                commandParameters[3] = DBHelper.createParameter("@TenDataBase", DbType.Int64, ParameterDirection.Input, this.mTenDataBase);
                commandParameters[4] = DBHelper.createParameter("@NguoiDung", DbType.Int64, ParameterDirection.Input, this.mNguoiDung);
                commandParameters[5] = DBHelper.createParameter("@MatKhau", DbType.Int64, ParameterDirection.Input, this.mMatKhau);
                commandParameters[6] = DBHelper.createParameter("@DatabaseLocal", DbType.Int64, ParameterDirection.Input, this.mDatabaseLocal);
                commandParameters[7] = DBHelper.createParameter("@KhoaKho", DbType.Int64, ParameterDirection.Input, this.mKhoaKho);
                bool flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "HT_sp_DataClient", commandParameters) > 0;
                flag2 = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag2 = false;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public string DatabaseLocal
        {
            get
            {
                return this.mDatabaseLocal;
            }
            set
            {
                this.mDatabaseLocal = value;
            }
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaKho
        {
            get
            {
                return this.mKhoaKho;
            }
            set
            {
                this.mKhoaKho = value;
            }
        }

        public int Loai
        {
            get
            {
                return this.mLoai;
            }
            set
            {
                this.mLoai = value;
            }
        }

        public string MatKhau
        {
            get
            {
                return this.mMatKhau;
            }
            set
            {
                this.mMatKhau = value;
            }
        }

        public string NguoiDung
        {
            get
            {
                return this.mNguoiDung;
            }
            set
            {
                this.mNguoiDung = value;
            }
        }

        public string TenDataBase
        {
            get
            {
                return this.mTenDataBase;
            }
            set
            {
                this.mTenDataBase = value;
            }
        }

        public string TenMayChu
        {
            get
            {
                return this.mTenMayChu;
            }
            set
            {
                this.mTenMayChu = value;
            }
        }
    }
}

